﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WindowsLive.Writer.Api;

namespace SP.LiveWriter.Publish
{
    public partial class Settings : Form
    {
        private IProperties properties;

        public Settings(IProperties prop)
        {
            properties = prop;
            InitializeComponent();
        }

        private void Settings_Load(object sender, EventArgs e)
        {
            if (properties != null)
            {
                if (properties.Contains(Constants.SiteUrl))
                    txtSite.Text = properties[Constants.SiteUrl];

                if (properties.Contains(Constants.ListName))
                    txtListName.Text = properties[Constants.ListName];

                if (properties.Contains(Constants.SiteUsername))
                    txtUsername.Text = properties[Constants.SiteUsername];

                if (properties.Contains(Constants.SitePassword))
                    txtPassword.Text = properties[Constants.SitePassword];
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtUsername.Text) ||
                string.IsNullOrEmpty(txtPassword.Text) ||
                string.IsNullOrEmpty(txtListName.Text) ||
                string.IsNullOrEmpty(txtSite.Text))
            {
                MessageBox.Show("You have incomplete information in the form.", "Incomplete data");
                properties[Constants.SiteUrl] = "";
                properties[Constants.ListName] = "";
                properties[Constants.SiteUsername] = "";
                properties[Constants.SitePassword] = "";
            }
            else
            {
                properties[Constants.SiteUrl] = txtSite.Text;
                properties[Constants.ListName] = txtListName.Text;
                properties[Constants.SiteUsername] = txtUsername.Text;
                properties[Constants.SitePassword] = txtPassword.Text;
            }
        }
    }
}
